home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Cream of the Crop 1
/
Cream of the Crop 1.iso
/
PROGRAM
/
CWL2A_1.ARJ
/
DEMO.C
< prev
next >
Wrap
C/C++ Source or Header
|
1991-11-16
|
33KB
|
1,056 lines
/* Date 11-1-91 */
/*********************************************************************
* This is the demonstration program of some of the functions *
* available with The C Window Library. *
* *
* For Turbo C version 1.5 and above, compile using the following: *
* tcc -mm -Ixxx demo.c tcwinm.lib *
* where xxx is the directory of The C Window Library header files. *
* *
* For Microsoft C users Version 5.1 and above: *
* cl -AM -Ixxx -DMSC demo /link /SE:1000 mswinm.lib *
* (use "qcl" instead of "cl" if using Quick C) *
* where xxx is the directory of The C Window Library header files. *
* *
* For Zortech C++ Version 2.0 and above: *
* ztc -mm -Ixxx -p -b demo.c zcwinm.lib *
* where xxx is the directory of The C Window Library header files. *
* *
* For Power C Version 2.1 and above: *
* pc -DPOWERC -mm -c -ixxx demo.c *
* pcl [5k,45k,300k] demo,pcwinm *
* where xxx is the directory of The C Window Library header files. *
*********************************************************************/
#include "window.h"
#include <stdio.h>
#include <dos.h>
int approx_delay(int);
void demo(void);
int write_all(WPOINTER);
void slide_window(WPOINTER);
int slide_windows(void);
int change_screen_size(void);
int read_file(void);
int pan_window(WPOINTER);
void resize_demo(void);
void last_function(void);
void slide_see_thru_window(WPOINTER);
void initialize_error(void);
void custom_error_func(int errcode, char *sourcefile, int sourceline,
char *funcname);
/* Define colors used */
#define YELLOWONRED CREATE_VIDEO_ATTRIBUTE(red,yellow)
#define WHITEONRED CREATE_VIDEO_ATTRIBUTE(red,lightwhite)
#define WHITEONBLUE CREATE_VIDEO_ATTRIBUTE(blue,white)
#define WHITEONBLACK CREATE_VIDEO_ATTRIBUTE(black,gray)
#define GREENONBLACK CREATE_VIDEO_ATTRIBUTE(black,green)
#define BLACKONWHITE CREATE_VIDEO_ATTRIBUTE(white,black)
#define WHITEONGREEN CREATE_VIDEO_ATTRIBUTE(green,white)
#define GRAYONBLACK CREATE_VIDEO_ATTRIBUTE(black,gray)
#define GREENONBLUE CREATE_VIDEO_ATTRIBUTE(blue,green)
#define NORM CREATE_VIDEO_ATTRIBUTE(black,white)
/* define filename characters */
#define FILENAMECHARS "25[A-Za-z0-9!@#$%/^&()+=_/-{}/[/]`~/.\\:]"
/* define titles used for each window */
char *title1 = " [ Main Window ] ";
char *title2 = " [ Window 1 ] ";
char *title3 = " [ Window 2 ] ";
char *title4 = " [ Window 3 ] ";
char filename[26]; /* filename buffer */
FILE *infile; /* input file handle */
/* Text written to main window */
char *screen1[] = {
" Welcome to the demonstration of the C Window Library!! The C Window Library",
" is a collection of C functions that manipulate text windows. With these ",
" text windows, you can ...",
NULL};
char *effectstr[] = {"Normal...",
"Normal Explode...",
"Contract...",
"Bricks...",
"Explode From Center To Top And Bottom...",
"Explode To Center From Top And Bottom...",
"Explode From Top...",
"Explode From Bottom...",
"Explode From Center To Left And Right...",
"Explode From Left And Right To Center...",
"Explode From Left To Right...",
"Explode From Right To Left..."
};
char *delay_text[] = {
"* Create Windows",
"* Write Text to Windows",
"* Hide Windows",
"* Resize Windows",
"* Get Input From Windows",
"* Scroll Up or Down in Windows",
"* Change Colors on the fly",
"* Create Shadows",
"* Create See-Thru Windows",
"* Border and Unborder Windows",
"* Use Windows Larger than the Physical Screen",
"* Create Pop-up, Bar, and PullDown Menus",
"* And Much More!",
NULL};
char *closing_message[] = {
"These are just a sample of the many things you can do with",
"The C Window Library!",
"The C Window Library is guaranteed to cut development time down substantially",
"without putting a lot of strain on your budget!",
" ",
"The full registered version of The C Window Library is only $50. ",
"With the full registered version you will receive technical support, free ",
"upgrades to the next major version, and the full source code. To receive ",
"the full registered version send check or money order for $50 to",
" ",
"P. A. McKenzie",
"CitySoft Software",
"100-3 Alcott Place",
"Bronx, NY 10475",
" ",
"Thank you for running the demo of The C Window Library!!",
};
WPOINTER main_window, /* Main Window */
help, /* Help Window */
esc_window, /* Escape Window */
error_window; /* Error Window */
WPOINTER w[3]; /* Window Pointers to miscellaneous
* windows */
VWPOINTER vw; /* Virtual window pointer */
VBLOCKPTR v; /* Video Block Pointer */
int error_check_flag = 1; /* Turn error checking on (not to be
* confused with the internal variable
* check_window_error) */
void main()
{
int i,d;
int initrow,initcol; /* Initial row and column of the cursor */
printf("\nPlease enter: '0' for Direct Screen Writes\n"
" '1' for Direct Screen Writes with snow checking\n"
" '2' for BIOS Screen updates: ");
scanf("%d",&d);
/* Get the cursor Position */
GetCursorPosition(&initrow,&initcol,0);
/* Initialize The C Window Library */
WindowInitializeSystem();
/* Initialize error function */
window_error_func = custom_error_func;
WindowSaveInitial(active_video_page);
initialize_error();
/* Initialize Direct memory writes, Snow check or BIOS screen updates
* depending on user's response */
CHECK_SNOW = d;
SCREEN_WRITE_METHOD = (d == 2)?BIOS:DMA;
/* Save Initial Screen as a VBLOCK and Clear Screen */
v = VideoSave(1,1,num_screen_rows,num_screen_cols);
ClearScreen(NORM);
/* Save What's on the screen now in a window - this gives us the base
* window to draw on */
/* Initialize and open help window */
help = WindowInitialize(NOBORDER,25,1,80,1,BLACKONWHITE,BLACKONWHITE,0);
WindowOpen(help);
WindowWriteCenterString(help,
"Up \030 Down \031 Left \033 Right \032 Quit <CR>",1);
/* Initialize and open main window */
main_window = WindowInitialize(BORDER, 1, 1, 78, 23,BLACKONWHITE,BLACKONWHITE, DOUBLEBOX);
WindowOpen(main_window);
/* Initialize and open escape window */
esc_window = WindowInitialize(BORDER,22,54,24,2,WHITEONBLUE,WHITEONBLUE,SINGLEBOX);
WindowOpen(esc_window);
WindowPrintf(esc_window,"Press ESC to Quit\nAny other key to advance");
/* Hide Cursor in main window */
WindowChangeCursor(main_window,INVISIBLE);
/* Write Some Strings to main window */
WindowWriteCenterString(main_window, "THE C WINDOW LIBRARY DEMO", 1);
WindowWriteCenterString(main_window, "─────────────────────────", 2);
WindowTitleTop(main_window, title1, TITLECENTER);
i = 0;
/* Display main window and escape window - make sure escape window is
* on top by making main window's rank = 2 and the escape window's
* rank = 1 */
WindowDisplay(main_window,2,NOEFFECT);
WindowDisplay(esc_window,1,NOEFFECT);
/* Write info to main window */
while (screen1[i] != NULL)
{
WindowWriteString(main_window, screen1[i], i+3, 1);
i++;
}
i = 0;
approx_delay(4000);
/* Write Slowly to main window */
while (delay_text[i] != NULL)
{
WindowWriteString(main_window, delay_text[i], i+9, 20);
i++;
approx_delay(2000);
}
approx_delay(15000);
/* Clear text from a region of the main window */
WindowClearRegion(main_window, 3, 1, 23, 78);
/* Call main demo() function */
demo();
/* Dispose of main window */
WindowFree(main_window,NOEFFECT);
/* Put original screen back and move cursor to startup position*/
}
void demo()
{
int i,j,k;
int dir;
char buf[50], buf2[50];
char *str = "You can also open multiple windows...";
buf[0] = 0;
/* Initialize and open sub-window 1 */
w[0] = WindowInitialize(BORDER, 15, 20, 38, 5, CREATE_VIDEO_ATTRIBUTE(blue, lightwhite),
CREATE_VIDEO_ATTRIBUTE(blue, lightwhite), SINGLEBOX);
WindowOpen(w[0]);
WindowWriteString(main_window,
"You can choose different border styles ...", 6, 1);
approx_delay(2000);
/* Demonstrate drawing a new border for main window. Also must rewrite
* title because title is destroyed when new border is written */
WindowDrawBorder(main_window,DOUBLEBOX);
approx_delay(2000);
WindowDrawBorder(main_window,MIXEDBOX1);
approx_delay(2000);
WindowDrawBorder(main_window,BLANKBOX);
approx_delay(2000);
WindowDrawBorder(main_window,SINGLEBOX);
approx_delay(2000);
/* Change main window's border attribute */
WindowWriteString(main_window,
"You can choose different border colors ...", 7, 1);
approx_delay(3000);
for (i=0;i<8;i++)
{
WindowChangeBorderAttribute(main_window,CREATE_VIDEO_ATTRIBUTE(i,lightwhite));
approx_delay(1000);
}
WindowChangeBorderAttribute(main_window,BLACKONWHITE);
/* Change main window's text attribute */
WindowWriteString(main_window,
"You can also choose different window colors ...", 8, 1);
approx_delay(3000);
for (i=0;i<8;i++)
{
WindowChangeTextAttribute(main_window,CREATE_VIDEO_ATTRIBUTE(i,lightwhite));
approx_delay(1000);
}
WindowChangeTextAttribute(main_window,BLACKONWHITE);
approx_delay(1000);
WindowClearRegion(main_window,3,1,9,70);
/* Title sub window 1 and display it */
WindowTitleTop(w[0],title2,TITLECENTER);
WindowDisplay(w[0],2,NOEFFECT);
/* Write text to sub window */
WindowWriteString(main_window,"You can write text to a window...",3,1);
approx_delay(1000);
WindowWriteString(w[0],"Hello, world!",1,1);
approx_delay(2000);
/* Demonstrate writing text with different colors */
WindowWriteString(main_window,
"You can write text with a different colors...",4,1);
approx_delay(2000);
WindowWriteStringAttr(w[0],"Hello, World!",2,1,BLACKONWHITE);
WindowWriteStringAttr(w[0],"Hello, World!",3,1,YELLOWONRED);
approx_delay(2000);
/* Demonstrate WindowPrintf() */
WindowWriteString(main_window,"You can even use a printf() for windows!",5,1);
approx_delay(2000);
WindowWriteString(main_window,"To demonstrate, I will count to 20...",6,1);
approx_delay(2000);
WindowMoveCursor(w[0],4,1);
for (i=1;i<=20;i++)
{
WindowPrintf(w[0],"Count is now %d\n",i);
approx_delay(1000);
}
approx_delay(4000);
WindowClear(w[0]);
/* Demonstrate right justification of strings in a window */
WindowWriteString(main_window,
"You can write Right Justified strings...",7,1);
approx_delay(2000);
WindowWriteStringRJ(w[0],"These strings",1,19);
WindowWriteStringRJ(w[0],"are printed Right",2,19);
WindowWriteStringRJ(w[0],"justified!",3,19);
approx_delay(4000);
/* Demonstrate centering strings around a column in a window */
WindowWriteString(main_window,
"You can write strings Centered on a certain column...",8,1);
approx_delay(2000);
WindowClear(w[0]);
WindowWriteStringCC(w[0],"These strings",1,10);
WindowWriteStringCC(w[0],"are centered on",2,10);
WindowWriteStringCC(w[0],"column 10",3,10);
approx_delay(3000);
WindowClear(w[0]);
WindowWriteStringCC(w[0],"These strings",1,19);
WindowWriteStringCC(w[0],"are centered on",2,19);
WindowWriteStringCC(w[0],"column 19",3,19);
approx_delay(3000);
WindowClear(w[0]);
WindowWriteStringCC(w[0],"These strings",1,29);
WindowWriteStringCC(w[0],"are centered on",2,29);
WindowWriteStringCC(w[0],"column 29",3,29);
approx_delay(3000);
WindowClearRegion(main_window,3,1,9,70);
WindowClear(w[0]);
/* Move sub window around on the screen */
WindowWriteString(main_window,"You can move a window around...",3,1);
approx_delay(2000);
for (i=1;i<=10;i++)
{
WindowMove(w[0],rand()%15+1,rand()%60+1);
approx_delay(1000);
}
WindowMove(w[0],14,12);
approx_delay(2000);
/* Slide sub window around on the screen */
WindowWriteString(main_window,"You can slide a window...",4,1);
WindowWriteString(main_window,"Press A key to Stop sliding...",5,1);
while (!ISKEYREADY())
{
dir = rand()%4+1;
if (dir == UP || dir == DOWN)
WindowSlide(w[0],dir,rand()%10+1);
else
WindowSlide(w[0],dir,rand()%30+1);
}
approx_delay(5000);
WindowMove(w[0],15,20);
WindowHide(w[0],NOEFFECT);
WindowClearRegion(main_window,3,1,9,70);
/* Erase and display main window using special effects */
WindowWriteString(main_window,
"You can remove a window from the screen using special effects",3,1);
approx_delay(4000);
for (i=0;i<=11;i++)
{
WindowWriteString(main_window,effectstr[i],i+4,1);
approx_delay(2000);
WindowHide(main_window,i);
approx_delay(2000);
WindowDisplay(main_window,2,i);
approx_delay(2000);
}
WindowClearRegion(main_window,3,1,15,70);
WindowWriteString(main_window, str, 3, 1);
approx_delay(5000);
/* Initialize, open, and display two more sub windows */
w[1] = WindowInitialize(BORDER, 12, 32, 38, 5, CREATE_VIDEO_ATTRIBUTE(green, lightwhite),
CREATE_VIDEO_ATTRIBUTE(green, lightwhite), SINGLEBOX);
WindowOpen(w[1]);
WindowWriteCenterString(w[1],title3,0);
w[2] = WindowInitialize(BORDER, 9, 38, 38, 5, BLACKONWHITE, BLACKONWHITE,
SINGLEBOX);
WindowOpen(w[2]);
WindowTitleTop(w[2],title4,TITLECENTER);
WindowDisplay(w[2],2,NOEFFECT);
WindowDisplay(w[1],2,NOEFFECT);
WindowDisplay(w[0],2,NOEFFECT);
WindowWriteString(w[1],"This is window 2",1,1);
WindowWriteString(w[2],"This is window 3",1,1);
WindowWriteString(w[0],"This is window 1",1,1);
approx_delay(2000);
/* Demonstrate writing text to any window at any time */
WindowWriteString(main_window,"You can write text to any window, at any time",4,1);
WindowWriteString(main_window,"regardless of which window is on top...",5,1);
approx_delay(3000);
write_all(w[0]);
approx_delay(2000);
write_all(w[1]);
approx_delay(2000);
write_all(w[2]);
approx_delay(2000);
/* Scroll text in sub windows to demonstrate independent scrolling */
WindowWriteString(main_window,"Press A key to stop scrolling...",7,1);
approx_delay(2000);
i = 1;
while (!ISKEYREADY())
{
WindowPrintf(w[0]," Scrolling line %d in window 1\n",i);
WindowPrintf(w[1]," Scrolling line %d in window 2\n",i);
WindowPrintf(w[2]," Scrolling line %d in window 3\n",i);
i++;
}
approx_delay(2000);
WindowWriteString(main_window,"You can change the order around...",8,1);
approx_delay(2000);
WindowHide(w[0],0);
WindowDisplay(w[0],2,0);
approx_delay(2000);
WindowDisplay(w[2],2,0);
approx_delay(2000);
WindowDisplay(w[1],2,0);
approx_delay(4000);
/* Slide all of the sub windows */
slide_windows();
approx_delay(4000);
/* Change the number of rows displayed on the screen */
change_screen_size();
WindowClearRegion(main_window,3,1,15,70);
/* Take off top two sub-windows windows */
WindowWriteString(main_window,"Let's remove the top two windows..",3,1);
approx_delay(2000);
WindowHide(w[1],NOEFFECT);
approx_delay(1000);
WindowHide(w[2],NOEFFECT);
approx_delay(1000);
WindowClear(w[0]);
/* Demonstrate see-thru window */
WindowWriteString(main_window,"You can create see-thru windows...",4,1);
approx_delay(2000);
WindowMakeSeeThru(w[0]);
approx_delay(2000);
WindowWriteString(main_window,
"Use Cursor Keys to move see-thru window around, RETURN to stop...",5,1);
/* Slide this see-thru window around */
slide_see_thru_window(w[0]);
/* Make see-thru windoqw a normal window again */
WindowMakeNormal(w[0]);
WindowClearRegion(main_window,3,1,15,70);
WindowWriteString(main_window,
"You can shadow window in 4 different positions...",3,1);
approx_delay(2000);
/* Draw Shadow on all 4 possible positions of the window */
WindowDrawShadow(w[0],SHADOWUPLEFT,2,1,'█',BLACKONWHITE,0);
approx_delay(2000);
WindowDrawShadow(w[0],SHADOWUPRIGHT,2,1,'█',BLACKONWHITE,0);
approx_delay(2000);
WindowDrawShadow(w[0],SHADOWLOWLEFT,2,1,'█',BLACKONWHITE,0);
approx_delay(2000);
WindowDrawShadow(w[0],SHADOWLOWRIGHT,2,1,'█',BLACKONWHITE,0);
approx_delay(4000);
WindowClearRegion(main_window,3,1,15,70);
WindowClearRegion(main_window,20,14,21,70);
WindowRemoveShadow(w[0]);
/* Demonstrate resizing sub-window */
WindowWriteString(main_window,"You can resize this window...",3,1);
approx_delay(4000);
resize_demo();
WindowWriteString(main_window,
"You can create windows larger than the physical screen ",3,1);
WindowWriteString(main_window,
"And scroll this window to see different sections",4,1);
approx_delay(5000);
/* Initialize a virtual window */
vw = VirtualInitialize(NOATTRIBUTE,80,80,0);
/* Read a file into the virtual window */
read_file();
/* Assign viewport to virtual window */
WindowAssignToVirtual(w[0],vw,1,1);
/* Make viewport larger */
WindowHide(w[0],NOEFFECT);
WindowMove(w[0],1,1);
WindowResizeWidth(w[0],78,ANCHORLEFT);
WindowResizeHeight(w[0],22,ANCHORTOP);
WindowDisplay(w[0],2,EXPLODE);
WindowDisplay(help,3,NOEFFECT);
WindowHide(esc_window,NOEFFECT);
/* Turn off error checking temporarily */
error_check_flag = 0;
pan_window(w[0]);
/* Turn error checking back on */
error_check_flag = 1;
WindowDisplay(esc_window,1,NOEFFECT);
/* Make viewport small again */
WindowHide(w[0],CONTRACT);
WindowHide(help,NOEFFECT);
WindowResizeWidth(w[0],38,ANCHORLEFT);
WindowResizeHeight(w[0],6,ANCHORTOP);
WindowMove(w[0],14,12);
/* Make viewport into a normal window again */
WindowCloseViewport(w[0],0,NOEFFECT);
WindowClearRegion(main_window,3,1,15,70);
WindowMoveCursor(main_window,15,1);
WindowMove(w[0],14,1);
WindowResizeWidth(w[0],78,ANCHORLEFT);
WindowDisplay(w[0],2,0);
/* Demonstrate input routines */
WindowWriteString(main_window,"You can also get input from windows...",3,1);
approx_delay(4000);
buf[0] = 0;
VirtualClear(vw);
WindowAssignToVirtual(w[0],vw,1,1);
WindowWriteString(w[0],"Enter Your First Name :",1,1);
/* Get a string */
WindowGetString(w[0],2,5,buf,'_',1,15,VIRTUALFIELD,1,"30.");
WindowMoveCursor(w[0],3,1);
WindowPrintf(w[0],"You entered %s",buf);
approx_delay(10000);
WindowWriteString(main_window,
"You can get input with a different attribute...",4,1);
approx_delay(10000);
/* Make sure input buffer's first character is null */
buf[0] = '\0';
WindowClear(w[0]);
WindowWriteString(w[0],"Enter Your Last Name :",1,1);
/* Get a string, but the attribute is reversed */
WindowGetStringAttr(w[0],2,1,buf,'_',1,15,0,1,BLACKONWHITE,"30.");
WindowMoveCursor(w[0],3,1);
WindowPrintf(w[0],"You entered %s",buf);
approx_delay(10000);
WindowWriteString(main_window,
"You can get input with an input mask ..",5,1);
buf[0] = 0;
WindowClear(w[0]);
/* Get a string using a character mask */
WindowWriteString(w[0],"Enter Your Social Security Number :",1,1);
WindowGetMaskString(w[0],2,1,buf,"___-__-____",'_',1,15,0,1,"9[0-9]");
WindowMoveCursor(w[0],3,1);
/* Use mask pattern to format output string */
TranslateStringToMaskString(buf,"___-__-____",buf2,'_',1);
WindowPrintf(w[0],"You entered %s",buf2);
approx_delay(10000);
buf[0] = 0;
WindowWriteString(main_window,
"You can get input with an input mask and have a different attribute..",6,1);
approx_delay(10000);
WindowClear(w[0]);
/* Get a string using a character mask, but use different attribute */
WindowWriteString(w[0],"Enter Your Social Security Number :",1,1);
WindowGetMaskStringAttr(w[0],2,1,buf,"___-__-____",'_',1,15,0,1,BLACKONWHITE,"9[0-9]");
WindowMoveCursor(w[0],3,1);
/* Use mask pattern to format output string */
TranslateStringToMaskString(buf,"___-__-____",buf2,'_',1);
WindowPrintf(w[0],"You entered %s",buf2);
approx_delay(10000);
buf[0] = 0;
WindowWriteString(main_window,"You can get password input...",7,1);
approx_delay(10000);
WindowClear(w[0]);
WindowWriteString(w[0],"Enter Your Name :",1,1);
/* Get password input */
WindowGetPassword(w[0],2,1,buf,'_','*',1,15,0,1,"30.");
WindowMoveCursor(w[0],3,1);
WindowPrintf(w[0],"You entered %s",buf);
approx_delay(10000);
buf[0] = 0;
WindowWriteString(main_window,
"You can get password input with a different attribute..",8,1);
approx_delay(10000);
WindowClear(w[0]);
WindowWriteString(w[0],"Enter Your Name :",1,1);
/* Get password but use different video attribute */
WindowGetPasswordAttr(w[0],2,1,buf,'_','*',1,15,0,1,BLACKONWHITE,"30.");
WindowMoveCursor(w[0],3,1);
WindowPrintf(w[0],"You entered %s",buf);
approx_delay(10000);
/* Hide all of the windows */
WindowHide(w[0],NOEFFECT);
WindowHide(main_window,NOEFFECT);
WindowHide(esc_window,NOEFFECT);
/* Clear the screen */
ClearScreen(NORM);
/* Demonstrate writing to the screen without using window functions */
VideoWriteString(
"You also have non-window related, fast video functions.",1,1);
VideoWriteString(
"To demonstrate, the normal printf() function will be used to fill the screen",2,1);
VideoWriteString("Press a key to start demonstration...",4,1);
GET_KEY();
/* Move Cursor to (1,1) */
MoveCursor(1,1,0);
/* Loop until all rows are filled with our message using normal printf() */
for (i=0; i<num_screen_rows; i++)
printf("Using the normal printf() function call\n");
printf("Press a key to demonstrate the C Window Libraries fast video ...");
GET_KEY();
/* Clear the screen */
ClearScreen(NORM);
/* Move Cursor to (1,1) */
MoveCursor(1,1,0);
/* Do same thing as before, but use VideoPrintf() */
for (i=0;i<num_screen_rows;i++)
VideoPrintf(
"Using the C Window Libraries VideoPrintf() function call\n");
approx_delay(20000);
last_function();
}
void last_function()
{
int i,j,k;
WindowFree(esc_window,NOEFFECT);
WindowClear(main_window);
/* Write closing message */
WindowWriteCenterString(main_window,closing_message[0],5);
for (i=2;i<=9;i++)
WindowWriteString(main_window,closing_message[i],i+6,1);
for (i=10;i<=13;i++)
WindowWriteCenterString(main_window,closing_message[i],i+6);
for (i=0;i<2;i++)
if (ISOPEN(w[i]))
WindowFree(w[i],NOEFFECT);
/* WindowDisplay(main_window,2,NOEFFECT);*/
i = 1;
/* Change video attribute until a key is pressed for the desired effect */
while(!ISKEYREADY())
{
j = i % 16;
if (j == 0)
j = 1;
k =
CREATE_VIDEO_ATTRIBUTE(GET_BGROUND_COLOR(WINDOW_TEXT_COLOR(main_window)),j);
WindowWriteCenterStringAttr(main_window,closing_message[1],6,k);
WindowWriteCenterStringAttr(main_window,closing_message[15],21,k);
i++;
delay(10);
}
VideoRestore(v);
MoveCursor(initial_video_startup.cursor_row,
initial_video_startup.cursor_col,0);
/* Change cursor back to original shape */
ChangeCursor(initial_video_startup.cursor_startline,
initial_video_startup.cursor_endline);
exit(0);
}
void resize_demo(void)
/************************************************************************
* This demo demonstrates the resizing features of the C Window Library *
***********************************************************************/
{
int i;
/* Get original width and height */
int h = WINDOW_HEIGHT(w[0]);
int wid = WINDOW_WIDTH(w[0]);
/* Resize Height of window. Also rewrite title because border text is
* destroyed when window is resized */
for (i=h+2;i<=17;i+=2)
{
WindowResizeHeight(w[0],i,ANCHORBOTTOM);
approx_delay(200);
}
for (i=17;i>=h;i-=2)
{
WindowResizeHeight(w[0],i,ANCHORTOP);
approx_delay(200);
}
for (i=h+2;i<=17;i+=2)
{
WindowResizeHeight(w[0],i,ANCHORTOP);
approx_delay(200);
}
for (i=17;i>=h;i-=2)
{
WindowResizeHeight(w[0],i,ANCHORBOTTOM);
approx_delay(200);
}
/* Resize width of window. Also rewrite title because border text is
* destroyed when window is resized */
for (i=wid+2;i<=60;i+=3)
{
WindowResizeWidth(w[0],i,ANCHORLEFT);
approx_delay(200);
}
for (i=60;i>=wid;i-=3)
{
WindowResizeWidth(w[0],i,ANCHORRIGHT);
approx_delay(200);
}
for (i=wid+2;i<=60;i+=3)
{
WindowResizeWidth(w[0],i,ANCHORRIGHT);
approx_delay(200);
}
for (i=60;i>=wid+2;i-=3)
{
WindowResizeWidth(w[0],i,ANCHORLEFT);
approx_delay(200);
}
}
/**********************************************************
* Gets a filename and displays it in the virtual window *
*********************************************************/
read_file()
{
int ch;
unsigned r = 1, c = 1;
infile = fopen("demo.c","r"); /* read file name into window */
while(1)
{
ch = fgetc(infile); /* get a character */
if (feof(infile))
break;
if (ch != '\n' && c <= 80) /* check if safe to write to virtual
* window */
VirtualWriteRepeatCharacter(vw,ch,r,c++,1); /* write character to vw */
else
{
if (c > 80)
/* read until '\n' is reached */
while((ch = fgetc(infile)) != '\n')
;
r++; /* increment row */
if (r > 80) break;
c=1;
}
}
fclose(infile); /* close input file */
return 0;
}
/* Write alphabet to window */
write_all(WPOINTER win)
{
int i;
for (i = 1; i <= WINDOW_HEIGHT(win); i++)
WindowWriteString(win,"ABCDEFGHIJKLMNOPQRSTUVWXYZ",i,1);
return 0;
}
/******************************
* Slide window demonstration *
*****************************/
void slide_see_thru_window(WPOINTER win)
{
int ch = 0;
/* Keep going until RETURN key is pressed */
while(ch != RETURN)
{
/* Get a key and slide 1 character in the desired direction */
switch(ch = GET_KEY())
{
case UARROW:
WindowSlide(win,UP,1);
break;
case DARROW:
WindowSlide(win,DOWN,1);
break;
case LARROW:
WindowSlide(win,LEFT,1);
break;
case RARROW:
WindowSlide(win,RIGHT,1);
break;
case 13:
WindowMove(win,14,12);
break;
}
}
}
/*********************************
* Scroll viewport demonstration *
********************************/
pan_window(WPOINTER win)
{
int ch = 0;
/* keep going until Escape or Return key is pressed */
/* Error checking is temporarily disabled because you may attempt to scroll
* beyond the bounds of the window */
while(ch != ESC && ch != RETURN)
{
switch(ch = GET_KEY())
{
case UARROW:
WindowScrollViewport(win,1,UP);
break;
case DARROW:
WindowScrollViewport(win,1,DOWN);
break;
case LARROW:
WindowScrollViewport(win,1,LEFT);
break;
case RARROW:
WindowScrollViewport(win,1,RIGHT);
break;
/* case ESC:
VideoRestore(v);
break; */
case RETURN:
break;
}
}
}
/* Delay function that either exits when you press a key, or when time
* runs out. Demo is terminated if ESC key is pressed */
approx_delay(int mil)
{
unsigned start = 5;
int ch;
/* quit if key is in keyboard buffer */
while(!ISKEYREADY())
{
delay(10);
start+=10;
/* return because time ran out */
if (start > mil)
return 0;
}
/* read the key */
ch = GET_KEY();
/* quit demo if the Escape key was pressed */
if (ch == ESC)
{
last_function();
}
return 0;
}
/**********************************************************************
* Changes screen rows. This routine exits if the hardware dowes not *
* support screen rows > 25 lines. *
*********************************************************************/
int change_screen_size()
{
int rows,oldrows = num_screen_rows;
WindowClearRegion(main_window,3,1,15,70);
WindowWriteString(main_window,"You can change screen size...",5,1);
approx_delay(5000);
/* Check for VGA mode */
if (VGA_MODE_ON)
SetVideoRows(rows=50,0);
else
/* Check for EGA or MCGA mode */
if (EGA_MODE_ON || MCGA_MODE_ON)
SetVideoRows(rows=43,0);
/* Video cannot change rows, so exit */
else
{
WindowWriteString(main_window,
"Sorry, your video adapter does not support more than 25 rows...",6,1);
approx_delay(8000);
return 0;
}
/* Adjust all global data in The C Window Library to reflect the new
* number of rows */
AdjustScreenInfo(0);
/* Resize the height of the main window */
WindowResizeHeight(main_window,rows-2,ANCHORTOP);
WindowWriteCenterString(main_window,title1,0);
/* Slide all sub-windows */
slide_windows();
WindowWriteString(main_window,"Press a key to change back to 25 rows",6,1);
GET_KEY();
/* Resize window. This must be done so that the window will fit in a
* 25 row screen (or whatever the old number of video rows were) */
WindowResizeHeight(main_window,oldrows-2,ANCHORTOP);
WindowWriteCenterString(main_window,title1,0);
SetVideoRows(oldrows,0);
/* Readjust global data */
AdjustScreenInfo(0);
return 0;
}
/* Slide all 3 sub-windows randomly */
slide_windows()
{
int i,j,k;
WindowWriteString(main_window,"Press a key to stop sliding...",9,1);
approx_delay(2000);
while (!ISKEYREADY())
{
i = rand()%3;
j = rand()%4+1;
if (j == UP || j == DOWN)
k = rand()%15+1;
else
k = rand()%50+1;
WindowSlide(w[i],j,k);
}
WindowMove(w[0],15,20);
WindowMove(w[1],14,14);
WindowMove(w[2],16,24);
return 0;
}
void initialize_error() /* Initialize error window and error handler */
{
error_window =
WindowInitialize(BORDER,1,1,60,5,WHITEONRED,WHITEONRED,SINGLEBOX);
WindowOpen(error_window);
window_error_func = custom_error_func; /* Assign error function */
}
void custom_error_func(int errcode, char *sourcefile, int sourceline,
char *funcname)
{
int ch;
if (error_check_flag)
{
MakeSound(100,500); /* Beep */
if (errcode == NO_HEAP_MEM) /* Always check for the heap memory error
separately */
{
VideoWriteString("You have ran out of Heap Memory",1,1);
VideoWriteString(
"Press 'Q' to quit program, Any other key to Continue...",2,1);
}
else /* Display error window */
{
WindowClear(error_window);
WindowDisplay(error_window,1,EXPLODE);
WindowPrintf(error_window,
"Error Code: %d\nSource File: %s\nSource Line %d\nError Occurred in %s",
errcode,sourcefile,sourceline,funcname);
WindowWriteString(error_window,
"Press 'Q' to quit program, Any other key to Continue...",5,1);
}
ch = GET_KEY();
if (ch == 'Q' || ch == 'q')
{
VideoRestore(v);
exit(0);
}
else
if (errcode != NO_HEAP_MEM)
WindowHide(error_window,CONTRACT);
}
}